package Frame.shopSet;

import FCRendering.FCRBattleOrderConstant;
import FCRendering.FCRMaster;
import FCRendering.sw.FCRValues;
import Frame.entity.UnifyShopSayUIEntity;
import Function.FCMutilPlayCache;
import VWorldGameStudio.*;
import lombok.Setter;
import socket.FCRSocketClient;
import socket.FCRSocketServer;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import static FCRendering.FCRMaster.*;

//按摩
public class FunctionAnMoShop extends AShopFuntion {
    private Vector<FixTank> needServiceNames = new Vector<>();


    FixTank selectFixTank = null;

    public FunctionAnMoShop() {
        buildShopWindow();
    }

    public void buildShopWindow() {
        needServiceNames.add(new FixTank(player1, player1.getName()));

        for (FCRPlayerLink link : FCMutilPlayCache.getTeamMembers()) {
            FCPlayerInfo p = FCMutilPlayCache.findPlayerByName(gameSave.HOST_UID, link.curPlayerName);
            needServiceNames.add(new FixTank(p, p.getChName()));
        }

        resetUI();
    }

    private void resetUI() {
        FCRValues.resetUnifySayUIEntity();
        FCRValues.leftWindowUI[0].leftText = "给谁按摩？";
        for (int i = 0; i < needServiceNames.size(); i++) {
            FixTank fixTank = needServiceNames.get(i);
            FCRValues.leftWindowUI[i + 1].leftText = fixTank.text;
        }
        FCRValues.rightWindowUI[6].rightText = "退出";
    }

    @Override
    public void clickLeftWindow(int i, UnifyShopSayUIEntity entity) {
        if (entity.leftText.length() > 1 && i > 0) {
            selectFixTank = needServiceNames.get(i - 1);
            FCPlayerInfo p = selectFixTank.playerInfo;
            FCRValues.rightWindowUI[0].rightText = "给" + selectFixTank.text + "按摩了一番";
            p.setPhysicalnum(p.getPhysical());
            if(p.getLongTermMap().containsKey(FCRBattleOrderConstant.S_Paralysis)) {
                p.getLongTermMap().remove(FCRBattleOrderConstant.S_Paralysis);
                List<FCPlayerInfo> needSyncRemoteBlood = new ArrayList<>();
                needSyncRemoteBlood.add(p);
                if (FCRMaster.fcv.isSever()) {
                    FCRSocketServer.getIn().syncPlayerState(needSyncRemoteBlood);
                } else if (FCRMaster.fcv.isClient()) {
                    FCRSocketClient.getIn().syncPlayerState(needSyncRemoteBlood);
                }
            }
        }
    }


    @Override
    public void clickRightWindow(int i, UnifyShopSayUIEntity entity) {
        switch (i) {
            case 6:
                fcv.setOpenSayShop(false);
                FCRMaster.fcv.setOpenSay(false);
                FCRMaster.fcv.setSayNpcName(null);
                FCRMaster.fcv.setSayNpcTextNum(0);
                break;
        }
    }
}
